package cn.doitedu.dp.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.*;

@Controller
public class HelloController {
    Connection connection;
    public HelloController() throws SQLException {
        connection = DriverManager.getConnection("jdbc:mysql://doitedu:3306/doit47","root","root");
    }



    @RequestMapping("/hello")
    @ResponseBody
    public String hello(String name){
        return "hello,"+name;
    }


    @RequestMapping("/login")
    public String login(String username,String password) throws SQLException {

        PreparedStatement pst = connection.prepareStatement("select password from ums_member where username = ?");
        pst.setString(1,username);

        ResultSet resultSet = pst.executeQuery();

        resultSet.next();
        String dbPassword = resultSet.getString("password");
        if(dbPassword.equals(password)){
            return "home.html";
        }else{
            return "login_error.html";
        }
    }
}
